package top.laoshuzi.scad.mosinnagant.utils

import eu.printingin3d.javascad.basic.Radius
import eu.printingin3d.javascad.coords.Coords3d
import eu.printingin3d.javascad.coords.Triangle3d
import eu.printingin3d.javascad.models.Abstract3dModel
import eu.printingin3d.javascad.models.Polyhedron
import eu.printingin3d.javascad.models.Sphere
import java.util.*

/**
 * Created by mouse on 2019/7/21.
 */
object ScadUtils {

    fun anchor(): Abstract3dModel {
        return Sphere(Radius.ZERO)
    }

    fun polyhedron(vertices: MutableList<Coords3d>, faces: Array<Array<Int>>): Polyhedron {
        val triangles = ArrayList<Triangle3d>()
        for (face in faces) {
            for (i in 1..face.size - 2) {
                triangles.add(
                    Triangle3d(
                        vertices[face[0]],
                        vertices[face[i]],
                        vertices[face[i + 1]]
                    )
                )
            }
        }
        return Polyhedron(triangles)
    }

}